/*
  请求地址:https://qiubao.ltd/球宝/index.php/Home/QiuBao/Find_Bill
  请求方法:get
  请求参数:无
  响应内容:账单信息

  1. 选择查询功能（账单信息，设备信息，商品信息，优惠劵信息等）
  2. 选择查询条件
  3. 渲染数据
  */



var Search_app = new Vue({
    el: "#Search_app",
    data: {
        table: '', //选择的表格
        tableList: ['订单信息', '设备信息', '优惠劵信息', '商品信息', '用户信息', '管理员信息'],
        device: '', //选择的设备
        deviceList: ['1号设备', '2号设备'],
        th: [], //表格字段头部
        tdata: [], //表格数据

        service_type: '', //服务类型
        service_List: ['全部', '饮品', '运动', '医护'], //服务类型List
        service_status: '',     //服务状态
        status_List: ['全部','已支付','未支付'],     //服务状态List
        service_year: '',      //服务时间

        device_location: '',        //设备区域
        location_List: ['全部','西区篮球场','东区篮球场'],           //设备区域List

        storage_state: '',              //库存状态
        storage_state_List: ['全部','充足','紧缺'],            //库存状态List

        device_name: '',       //设备name

        coupon_name: '',    //优惠劵名
        goods_name:'',
        goods_type:'',

        goods_typeList: ['全部','运动','饮品','医护']
    },
    created() {
        //如果没有这句代码，select中初始化会是空白的，默认选中就无法实现
        console.log("初始化create!")
        this.table = this.tableList[0];
        console.log(this.table)
        this.service_type = this.service_List[0]
        this.service_status = this.status_List[0]
        this.goods_type = this.goods_typeList[0]
        this.device_location = this.location_List[0]
        this.storage_state = this.storage_state_List[0]
        var that = this
        axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_Bill", {
            'service_type': that.service_type,
            'service_status': that.service_status,
            'service_year': that.service_year,
        }, {
            transformRequest: [function (data) {
                var str='';
                for (var key in data) {
                    str += encodeURIComponent(key) + '=' + encodeURIComponent(data[key]) + '&';
                }
                return str;
            }]
        })
            .then(function(response) {
                console.log(response);
                // console.log(response.data.data);
                that.tdata = response.data.data;
            })
            .catch(function(err) {})
    },
    methods:{
        getgoods:function(){
            console.log('您执行了getgoods方法')
            var that = this
            axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_goods", {
                'goods_name': that.goods_name,
                'goods_type': that.goods_type,
            }, {
                transformRequest: [function (data) {
                    var str='';
                    for (var key in data) {

                        str += encodeURIComponent(key) + '=' + encodeURIComponent(data[key]) + '&';
                    }
                    return str;
                }]
            })
                .then(function(response) {
                    console.log(response);
                    // console.log(response.data.data);
                    that.tdata = response.data.data;
                })
                .catch(function(err) {})
        },
        getcoupon:function(){
            console.log('您执行了getcoupon方法')
            var that = this
            axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_coupons", {
                'coupon_name': that.coupon_name,
            }, {
                transformRequest: [function (data) {
                    var str='';
                    for (var key in data) {

                        str += encodeURIComponent(key) + '=' + encodeURIComponent(data[key]) + '&';
                    }
                    return str;
                }]
            })
                .then(function(response) {
                    console.log(response);
                    // console.log(response.data.data);
                    that.tdata = response.data.data;
                })
                .catch(function(err) {})
        },
        getdevice: function(){
            console.log("您选择了getdevice")
            var that = this
            axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_device", {
                'device_location': that.device_location,
                'storage_state': that.storage_state,
                'device_name': that.device_name,
            }, {
                transformRequest: [function (data) {
                    var str='';
                    for (var key in data) {
                        str += encodeURIComponent(key) + '=' + encodeURIComponent(data[key]) + '&';
                    }
                    return str;
                }]
            })
                .then(function(response) {
                    console.log(response);
                    // console.log(response.data.data);
                    that.tdata = response.data.data;
                })
                .catch(function(err) {})
        },
        get_service: function() {
            console.log('您选择了', this.service_type)
            var that = this
            axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_Bill", {
                'service_type': that.service_type,
                'service_status': that.service_status,
                'service_year': that.service_year,
            }, {
                transformRequest: [function (data) {
                    var str='';
                    for (var key in data) {
                        str += encodeURIComponent(key) + '=' + encodeURIComponent(data[key]) + '&';
                    }
                    return str;
                }]
            })
                .then(function(response) {
                    console.log(response);
                    // console.log(response.data.data);
                    that.tdata = response.data.data;
                })
                .catch(function(err) {})
        },
        getValue: function() {
            console.log('您选择了', this.table)
                // this.tdata = []
                // 调用接口
                // 保存this
            var that = this;
            if (that.table == '订单信息') {
                axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_Bill", {
                    'service_type': that.service_type,
                    'service_status': that.service_status,
                    'service_year': that.service_year,
                }, {
                    transformRequest: [function (data) {
                        var str='';
                        for (var key in data) {
                            str += encodeURIComponent(key) + '=' + encodeURIComponent(data[key]) + '&';
                        }
                        return str;
                    }]
                })
                    .then(function(response) {
                        console.log(response);
                        // console.log(response.data.data);
                        that.tdata = response.data.data;
                    })
                    .catch(function(err) {})
            }
            if (that.table == '优惠劵信息') {
                axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_coupons")
                    .then(function(response) {
                        console.log(response);
                        // console.log(response.data.data);
                        that.tdata = response.data.data;
                    })
                    .catch(function(err) {})
            }
            if (that.table == '商品信息') {
                axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_goods")
                    .then(function(response) {
                        console.log(response);
                        // console.log(response.data.data);
                        that.tdata = response.data.data;
                    })
                    .catch(function(err) {})
            }
            if (that.table == '用户信息') {
                axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_users")
                    .then(function(response) {
                        console.log(response);
                        // console.log(response.data.data);
                        that.tdata = response.data.data;
                    })
                    .catch(function(err) {})
            }
            if (that.table == '管理员信息') {
                axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_Manager")
                    .then(function(response) {
                        console.log(response);
                        // console.log(response.data.data);
                        that.tdata = response.data.data;
                    })
                    .catch(function(err) {})
            }
            if (that.table == '设备信息') {
                axios.post("https://qiubao.ltd/球宝/index.php/Home/QiuBaoWeb/Find_device")
                    .then(function(response) {
                        console.log(response);
                        // console.log(response.data.data);
                        that.tdata = response.data.data;
                    })
                    .catch(function(err) {})
            }
        },
        Search: function() {

        }


    }
})